﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SharingCenter.Web.Classes.Contact;

namespace SharingCenter.Web.Shared
{
    public partial class ContactList : System.Web.UI.UserControl
    {
        Guid uid;
        bool uidSet = false;
        public Guid UserId { get { return uid; } set { uid = value; uidSet = true; } }
        public string CssClass { get; set; }

        protected string tdwidth;
        int itemsPerRow = 0;
        public int ItemsPerRow { get { return itemsPerRow; } set { itemsPerRow = value; tdwidth = string.Format("{0}%", 100 / value); } }
        
        void Page_Init(object sender, EventArgs e)
        {
            this.PreRender += new EventHandler(ContactList_PreRender);
            LinqDataSource1.Selecting += new EventHandler<LinqDataSourceSelectEventArgs>(LinqDataSource1_Selecting);
        }

        void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
        {
            Guid userId = uidSet ? uid : WebProfile.Current.UserId;
            e.Result = ContactOperations.GetContacts(userId);
        }

        void ContactList_PreRender(object sender, EventArgs e)
        {
            Panel1.CssClass = this.CssClass;
            ListView1.GroupItemCount = itemsPerRow;
        }

        void Page_Load(object sender, EventArgs e)
        {
            
        }
    }
}